package com.example.yuejian.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.yuejian.Bean.PostComment;
import com.example.yuejian.R;
import com.example.yuejian.UnitData;
import com.example.yuejian.data.CircleImageView;
import com.squareup.picasso.Picasso;

import java.util.List;


public class CommentAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
    private Context mContext;
    private List<PostComment.ComListBean> mList;
    public LayoutInflater mLayoutInflater;

    public CommentAdapter(Context mContext, List<PostComment.ComListBean> List) {
        this.mContext = mContext;
        this.mList = List;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_comment, parent, false);
        CommentAdapter.ViewHolder v = new CommentAdapter.ViewHolder(view);

        return v;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final PostComment.ComListBean club = (PostComment.ComListBean) mList.get(position);
        if (null == club)
            return;
        CommentAdapter.ViewHolder viewHolder = (CommentAdapter.ViewHolder) holder;
        viewHolder.name.setText(club.getCom_name());
        viewHolder.tiem.setText(club.getCommtime());
        viewHolder.content.setText(club.getContent());
        Picasso.with(mContext).load(UnitData.IMG_URL+club.getPic()).into(viewHolder.img_pic);


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name,tiem,content;
        CircleImageView img_pic;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);
            tiem = (TextView) itemView.findViewById(R.id.tiem);
            content = (TextView) itemView.findViewById(R.id.content);
            img_pic = (CircleImageView) itemView.findViewById(R.id.img_pic);

        }
    }
}
